<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="true">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="缴费账号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="code">
              <a-input v-model="model.code" placeholder="请输入缴费账号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="账户类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="feeCusType">
              <j-dict-select-tag type="list" v-model="model.feeCusType" dictCode="fee_cus_type" placeholder="请选择账户类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="账号名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contactId">
              <j-search-select-tag v-model="model.contactId" dict="mws_t_arc_contacts,name,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="账户状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="waterUserStatus">
              <j-dict-select-tag type="list" v-model="model.waterUserStatus" dictCode="water_user_status" placeholder="请选择账户状态,1正常,2停用,3销户" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否预存" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isStored">
              <j-dict-select-tag type="list" v-model="model.isStored" dictCode="yn" placeholder="请选择是否预存账户" />
            </a-form-model-item>
          </a-col>
           <a-col :span="12">
            <a-form-model-item label="账户余额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="balance">
              <a-input-number v-model="model.balance" placeholder="请输入账户余额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
           <a-col :span="12">
            <a-form-model-item label="微信ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="weixinId">
              <a-input v-model="model.weixinId" placeholder="请输入微信账户ID"  ></a-input>
            </a-form-model-item>
          </a-col>


        <!-- 
          <a-col :span="8">
            <a-form-model-item label="银行账号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bankAccountNo">
              <a-input v-model="model.bankAccountNo" placeholder="请输入银行账号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="开户行" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bank">
              <a-input v-model="model.bank" placeholder="请输入开户行"  ></a-input>
            </a-form-model-item>
          </a-col>          
         
          <a-col :span="8">
            <a-form-model-item label="预存协议号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="storedContractNo">
              <a-input v-model="model.storedContractNo" placeholder="请输入预存协议号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="预存开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="storedBeginTime">
              <a-input v-model="model.storedBeginTime" placeholder="请输入预存开始时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="预存结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="storedEndTime">
              <a-input v-model="model.storedEndTime" placeholder="请输入预存结束时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="预存创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="storedCreatedTime">
              <a-input v-model="model.storedCreatedTime" placeholder="请输入预存创建时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="预存创建人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="storedCreatorId">
              <a-input v-model="model.storedCreatorId" placeholder="请输入预存创建人"  ></a-input>
            </a-form-model-item>
          </a-col>         
          <a-col :span="8">
            <a-form-model-item label="滚存金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="roundBalance">
              <a-input-number v-model="model.roundBalance" placeholder="请输入滚存金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="是否托收" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isProxy">
              <j-dict-select-tag type="list" v-model="model.isProxy" dictCode="yn" placeholder="请选择是否托收" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="托收单位ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="feeProxyUnit">
              <a-input v-model="model.feeProxyUnit" placeholder="请输入托收单位ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="是否预开票" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isPreInvoiced">
              <j-dict-select-tag type="list" v-model="model.isPreInvoiced" dictCode="yn" placeholder="请选择是否预开票" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="是否增值税" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isVat">
              <j-dict-select-tag type="list" v-model="model.isVat" dictCode="yn" placeholder="请选择是否增值税" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="增值税号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="vatNo">
              <a-input v-model="model.vatNo" placeholder="请输入增值税号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="银行合同号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bankcontractno">
              <a-input v-model="model.bankcontractno" placeholder="请输入银行合同号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="开户行号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bankno">
              <a-input v-model="model.bankno" placeholder="请输入开户行号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="托收户是否审核" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isExamine">
              <j-dict-select-tag type="list" v-model="model.isExamine" dictCode="yn" placeholder="请选择托收户是否审核" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="银行开户名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bankaccountname">
              <a-input v-model="model.bankaccountname" placeholder="请输入银行开户名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="银行开启时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bankOpendTime">
              <a-input v-model="model.bankOpendTime" placeholder="请输入银行开启时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">
              <a-input-number v-model="model.status" placeholder="请输入状态" style="width: 100%" />
            </a-form-model-item>
          </a-col> 
         
          <a-col :span="8">
            <a-form-model-item label="是否银行代扣" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isWithhold">
              <j-dict-select-tag type="list" v-model="model.isWithhold" dictCode="yn" placeholder="请选择是否银行代扣" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="代扣银行" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="withholdBank">
              <a-input v-model="model.withholdBank" placeholder="请输入代扣银行"  ></a-input>
            </a-form-model-item>
          </a-col>
          -->
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'ArcAccountForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      },   
      accCode:{
        type: String,       
        default: ''
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           code: [
              { required: true, message: '请输入缴费账号!'},
           ],
           feeCusType: [
              { required: true, message: '请输入账户类型!'},
           ],
           contactId: [
              { required: true, message: '请输入用户档案!'},
           ],
           waterUserStatus: [
              { required: true, message: '请输入账户状态,1正常,2停用,3销户!'},
           ],
           isStored: [
              { required: true, message: '请输入是否预存账户!'},
           ],
           balance: [
              { required: true, message: '请输入账户余额!'},
           ],
           roundBalance: [
              { required: true, message: '请输入滚存金额!'},
           ],
           isProxy: [
              { required: true, message: '请输入是否托收!'},
           ],
           isPreInvoiced: [
              { required: true, message: '请输入是否预开票!'},
           ],
           isVat: [
              { required: true, message: '请输入是否增值税!'},
           ],           
        },
        url: {
          add: "/arc/arcAccount/add",
          edit: "/arc/arcAccount/edit",
          queryById: "/arc/arcAccount/queryById",
          queryByCode: "/arc/arcAccount/queryByCode"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));     
      if(this.accCode){
        this.loadBaseData();
      }
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        // this.model = Object.assign({}, record);
        this.visible = true;
      },
      loadBaseData(){
        const that = this;      
        let param={
          accCode: this.accCode
        }
        getAction(that.url.queryByCode,param).then((res)=>{ 
          if(res.success){
            that.model=res.result; 
          }else{
            that.$message.warning(res.message);
          }
        })
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>